package uestc.lj.basic.sort;

/**
 * 数组中寻找出现奇数次的数
 *
 * @Author:Crazlee
 * @Date:2021/11/20
 */
public class Code3_EvenOddTimes {
    public static void printOddTimes(int[] array) {
        int eor = 0, onlyOne = 0;
        for (int arr : array) {
            eor ^= arr;
        }
        //提取最右位的1
        int rightOne = eor & (~eor + 1);

        for (int cur : array) {
            if ((cur & rightOne) == 1) {
                onlyOne ^= cur;
            }
        }
        System.out.println("出现奇数次的第一个数是：" + onlyOne + "，第二个数是：" + (onlyOne ^ eor));
    }

    public static void main(String[] args) {
        int[] array = {7, 7, 5, 5, 6, 6, 3, 3, 1, 9, 9, 8};
        printOddTimes(array);
    }
}
